-- onyxfox_guildxp
local _, guildxp = ...
guildxp.numquests = 0
guildxp.eventframe = CreateFrame("Frame")
guildxp.eventframe:SetScript("OnEvent", function(self, event, ...)

	if (event == "PLAYER_ENTERING_WORLD") or (event == "QUEST_FINISHED") then
		-- Check that we are in a guild.
		if not IsInGuild() then
			-- print("Not in a guild.")
			self:UnregisterAllEvents()
			return
		end
		QueryGuildXP()
	end

	if (event == "GUILD_XP_UPDATE") then
		local _, nxp = UnitGetGuildXP("player")
		if guildxp.numquests ~= floor(nxp/60000) then
			print(string.format("|cff8080FFonyxfox|rGuildXP: %d quests to level.", floor(nxp/60000)))
			guildxp.numquests = floor(nxp/60000)
		end
	end

end)
guildxp.eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
guildxp.eventframe:RegisterEvent("GUILD_XP_UPDATE")
guildxp.eventframe:RegisterEvent("QUEST_FINISHED")
